﻿using System;
using System.Reflection;
using élénkPróbája.attributes;

namespace élénkPróbája.native
{
    internal static class Compilation
    {
        public static Func<string> CreateGetter(this PropertyInfo property)
        {
            return (Func<string>) Delegate.CreateDelegate(typeof (Func<string>), property.GetGetMethod());
        }

        public static ValidatorAttribute GetValidatorAttribute(this Type type)
        {
            return (ValidatorAttribute) Attribute.GetCustomAttribute(type, typeof (ValidatorAttribute));
        }

        public static ValidatorAttribute GetValidatorAttribute(this ParameterInfo parameterInfo)
        {
            return
                (ValidatorAttribute)
                    Attribute.GetCustomAttribute(parameterInfo, typeof (ValidatorAttribute));
        }

        public static Assembly GetAssembly(this Type type)
        {
            return type.Assembly;
        }

        public static MethodInfo GetDeclaredMethod(this Type type, string name)
        {
            return type.GetMethod(name, new Type[0]);
        }

        public static bool IsGenericType(this Type type)
        {
            return type.IsGenericType;
        }
    }
}